
#include "iostream"
#include "vector"
#include "unordered_map"
#include "unordered_set"
#include "algorithm"
#include "string"
#include "list"
#include "string.h"

class OneLoop {
public:
    uint64_t fast_mi(uint64_t a,uint64_t b,uint64_t p){
        if(b==0){
            return 1;
        }else if(b%2==0){
            //关键！
            uint64_t temp=fast_mi(a,b/2,p);
            return (temp*temp)%p;
        }else{
            return ((a%p)* fast_mi(a,b-1,p))%p;
        }
    }

    bool run(
    ) {
        uint64_t a=UINT64_MAX,b=UINT64_MAX,c=UINT64_MAX;
        if(scanf_s("%llu %llu %llu",&a,&b,&c)!=EOF){
            printf("%llu", fast_mi(a,b,c)%c);
            return true;
        }else{
            return false;
        }
    }
};

class Solution {
public:
    void run() {

        bool first = true;
        int a, b, c, d, e;
//        std::cin >> a;
        while (1) {
            OneLoop l;
            if (!l.run()) {
                return;
            }
            a--;
        }


    }
};

int main() {
//    bool cur_num= true;
    Solution().run();
    return 0;
}

